package com.bkq.viettravel;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import bkq.viettravel.bll.ImageBLL;
import bkq.viettravel.dto.ImageDTO;

import com.bkq.viettravel.CustomAdapter.ViewHold;

import android.app.Activity;
import android.app.ListActivity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class ListImage extends Activity {
	private ListView listImage;
	private ArrayList<ImageDTO> listItem;
	private ImageBLL imageBll = null;
	private int idTravel = 0;
	private Button back ;
	
	public void onCreate(Bundle savedInstanceState)  {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_images);
		
		
		
		Bundle extras = getIntent().getExtras();
		if(extras != null)
		{
			idTravel = extras.getInt("idTravel");
		}
		
		listImage = (ListView)findViewById(R.id.listImage);
		listItem = new ArrayList<ImageDTO>();
		imageBll = new ImageBLL(this);
		if(idTravel != 0)
			listItem = imageBll.getByIdTravel(idTravel);
		
		
	    CustomAdapter adapte = new CustomAdapter(this,listItem);
	    listImage.setAdapter(adapte);
	    
	    
		
		
	} 
	
	class CustomAdapter extends BaseAdapter {
		LayoutInflater mInflate ;
		ArrayList<ImageDTO> mlist ;
		
		public CustomAdapter(Context contex, ArrayList<ImageDTO> list) {
			mInflate = LayoutInflater.from(contex);
			mlist = list;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mlist.size();
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return mlist.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHold holder = new ViewHold();
			if(convertView == null)
			{
				convertView = mInflate.inflate(R.layout.list_image_row,null);
				holder.img = (LoaderImageView) convertView.findViewById(R.id.img);
				
				convertView.setTag(holder);
			}
			
			else
			{
				holder = (ViewHold)convertView.getTag();
			}
			
				
				holder.img.setImageDrawable(mlist.get(position).getLinkImage(), 90, 120);
			return convertView;
		}
		
		class ViewHold
		{
			public LoaderImageView img;
			
			
		}
	}
}
